Skip to main content

Getting started with Python

Usage Example in Python

An example written in Python 3.7 should provide the user with the necessary tools to get started with using the API. The following sections walk you through the process to authenticate with the API and request raw telemetry data.

For the example to work import the following Python packages at the top of your file and define some constants to work with later on. Don't forget to set the IMO constant to the IMO number of the ship you want to query data for.

Here, we use the requests package which you can install e.g. via pip install requests.

import os
import requests

IMO = "2000063"
API_URL = "https://api.hoppe-sts.com/"
API_KEY = os.getenv("STS_API_KEY")

Authentication

Authentication and authorization is handled via an API key. Please consult the Getting Started page for details regarding API key generation. In this example, we retrieve the API key from the environment variable STS_API_KEY.

Data Access

info

The time series API requires the Data Butler Quality package.

With this API key at hand we can proceed to (for example) request the available data for a specified ship in a given time period:

# Request the file list.
request_url = f"{API_URL}ships/{IMO}/data/files?format=sqlite&from_date=2020-10-01T00:00:00"
data_files = requests.request("GET", request_url, headers={"Authorization": f"ApiKey {API_KEY}"})

This example should get you easily started with using Python to access your data in the cloud.

caution

Please always treat each API key as secret and do not share it with any unauthorized persons. An API key allows access to some of your most valuable assets: your data.